package com.jxw.utils;

import android.util.Log;
import org.apache.commons.net.SocketClient;

/* loaded from: classes.dex */
public class Logger {
    private static boolean debug = true;
    private static Logger instance = new Logger();
    private String tag = "debug";

    private Logger() {
    }

    public static Logger getLogger() {
        return instance;
    }

    private String getFunctionName() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        if (stackTrace == null) {
            return null;
        }
        for (StackTraceElement stackTraceElement : stackTrace) {
            if (!stackTraceElement.isNativeMethod() && !stackTraceElement.getClassName().equals(Thread.class.getName()) && !stackTraceElement.getClassName().equals(getClass().getName())) {
                return "[" + Thread.currentThread().getName() + "(" + Thread.currentThread().getId() + "): " + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + "]";
            }
        }
        return null;
    }

    private String createMessage(String str) {
        String functionName = getFunctionName();
        if (functionName == null) {
            return str;
        }
        return functionName + " - " + str;
    }

    public void i(String str) {
        if (debug) {
            Log.i(this.tag, createMessage(str));
        }
    }

    public void v(String str) {
        if (debug) {
            Log.v(this.tag, createMessage(str));
        }
    }

    public void d(String str) {
        if (debug) {
            Log.d(this.tag, createMessage(str));
        }
    }

    public void e(String str) {
        Log.e(this.tag, createMessage(str));
    }

    public void error(Exception exc) {
        if (debug) {
            StringBuffer stringBuffer = new StringBuffer();
            String functionName = getFunctionName();
            StackTraceElement[] stackTrace = exc.getStackTrace();
            if (functionName != null) {
                stringBuffer.append(functionName + " - " + exc + SocketClient.NETASCII_EOL);
            } else {
                stringBuffer.append(exc + SocketClient.NETASCII_EOL);
            }
            if (stackTrace != null && stackTrace.length > 0) {
                for (StackTraceElement stackTraceElement : stackTrace) {
                    if (stackTraceElement != null) {
                        stringBuffer.append("[ " + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + " ]\r\n");
                    }
                }
            }
            Log.e(this.tag, stringBuffer.toString());
        }
    }

    public void w(String str) {
        if (debug) {
            Log.w(this.tag, createMessage(str));
        }
    }

    public void setTag(String str) {
        this.tag = str;
    }

    public static void setDebug(boolean z) {
        debug = z;
    }

    public static boolean isDebug() {
        return debug;
    }
}
